<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"><title>Ajax第一天 | XC's Blog</title><meta name="keywords" content="Ajax笔记"><meta name="author" content="XC's Blog"><meta name="copyright" content="XC's Blog"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="Ajax第一天 – ajax概念 – axios的使用 – HTTP协议知识点自测 如下对象取值的方式哪个正确? 123let obj &#x3D; &amp;#123;    name: &amp;#x27;黑马&amp;#x27;&amp;#125;  A: obj.a B: obj()a  答案  A选项正确      哪个赋值会让浏览器解析成标签显示? 12let ul &#x3D; document.querySelector(&amp;#x27"><meta property="og:type" content="article"><meta property="og:title" content="Ajax第一天"><meta property="og:url" content="https://webxc.eu.org/post/as67/index.html"><meta property="og:site_name" content="XC&#39;s Blog"><meta property="og:description" content="Ajax第一天 – ajax概念 – axios的使用 – HTTP协议知识点自测 如下对象取值的方式哪个正确? 123let obj &#x3D; &amp;#123;    name: &amp;#x27;黑马&amp;#x27;&amp;#125;  A: obj.a B: obj()a  答案  A选项正确      哪个赋值会让浏览器解析成标签显示? 12let ul &#x3D; document.querySelector(&amp;#x27"><meta property="og:locale" content="zh_CN"><meta property="og:image" content="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/ajax.webp"><meta property="article:published_time" content="2023-05-31T23:30:00.000Z"><meta property="article:modified_time" content="2023-08-30T18:00:49.013Z"><meta property="article:author" content="XC&#39;s Blog"><meta property="article:tag" content="Ajax笔记"><meta name="twitter:card" content="summary"><meta name="twitter:image" content="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/ajax.webp"><link rel="shortcut icon" href="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><link rel="canonical" href="https://webxc.eu.org/post/as67/"><link rel="preconnect" href="//cdn.jsdelivr.net"><link rel="preconnect" href="//busuanzi.ibruce.info"><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://npm.elemecdn.com/@fortawesome/fontawesome-free@6.2.0/css/all.min.css" media="print" onload='this.media="all"'><link rel="stylesheet" href="https://npm.elemecdn.com/node-snackbar/dist/snackbar.min.css" media="print" onload='this.media="all"'><link rel="stylesheet" href="https://npm.elemecdn.com/@fancyapps/ui/dist/fancybox.css" media="print" onload='this.media="all"'><script>const GLOBAL_CONFIG={root:"/",algolia:void 0,localSearch:{path:"/search.xml",preload:!1,languages:{hits_empty:"找不到您查询的内容：${query}"}},translate:void 0,noticeOutdate:void 0,highlight:{plugin:"highlighjs",highlightCopy:!0,highlightLang:!0,highlightHeightLimit:!1},copy:{success:"吾辈宣布,你的剪切板已被占领",error:"呀~复制失败,请在尝试下",noSupport:"对不起,你的浏览器不支持"},relativeDate:{homepage:!1,post:!1},runtime:"",date_suffix:{just:"刚刚",min:"分钟前",hour:"小时前",day:"天前",month:"个月前"},copyright:{limitCount:60,languages:{author:"作者: XC's Blog",link:"链接: ",source:"来源: XC's Blog",info:"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},lightbox:"fancybox",Snackbar:{chs_to_cht:"您已切换为繁体",cht_to_chs:"您已切换为简体",day_to_night:"您已切换为深色主题",night_to_day:"您已切换为浅色主题",bgLight:"#3b70fc",bgDark:"#121212",position:"bottom-center"},source:{justifiedGallery:{js:"https://npm.elemecdn.com/flickr-justified-gallery/dist/fjGallery.min.js",css:"https://npm.elemecdn.com/flickr-justified-gallery/dist/fjGallery.css"}},isPhotoFigcaption:!1,islazyload:!0,isAnchor:!0}</script><script id="config-diff">var GLOBAL_CONFIG_SITE={title:"Ajax第一天",isPost:!0,isHome:!1,isHighlightShrink:!1,isToc:!0,postUpdate:"2023-08-30 18:00:49"}</script><noscript><style>#nav{opacity:1}.justified-gallery img{opacity:1}#post-meta time,#recent-posts time{display:inline!important}</style></noscript><script>(e=>{e.saveToLocal={set:function(e,t,o){if(0===o)return;const n=864e5*o,a={value:t,expiry:(new Date).getTime()+n};localStorage.setItem(e,JSON.stringify(a))},get:function(e){const t=localStorage.getItem(e);if(!t)return;const o=JSON.parse(t);if(!((new Date).getTime()>o.expiry))return o.value;localStorage.removeItem(e)}},e.getScript=e=>new Promise(((t,o)=>{const n=document.createElement("script");n.src=e,n.async=!0,n.onerror=o,n.onload=n.onreadystatechange=function(){const e=this.readyState;e&&"loaded"!==e&&"complete"!==e||(n.onload=n.onreadystatechange=null,t())},document.head.appendChild(n)})),e.activateDarkMode=function(){document.documentElement.setAttribute("data-theme","dark"),null!==document.querySelector('meta[name="theme-color"]')&&document.querySelector('meta[name="theme-color"]').setAttribute("content","#0d0d0d")},e.activateLightMode=function(){document.documentElement.setAttribute("data-theme","light"),null!==document.querySelector('meta[name="theme-color"]')&&document.querySelector('meta[name="theme-color"]').setAttribute("content","#ffffff")};const t=saveToLocal.get("theme");"dark"===t?activateDarkMode():"light"===t&&activateLightMode();const o=saveToLocal.get("aside-status");void 0!==o&&("hide"===o?document.documentElement.classList.add("hide-aside"):document.documentElement.classList.remove("hide-aside"));/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)&&document.documentElement.classList.add("apple")})(window)</script><link rel="stylesheet" href="https://cdn1.tianli0.top/gh/web-xc/My-blog-CSS/mgi.css"><link rel="stylesheet" href="https://cdn1.tianli0.top/gh/web-xc/My-blog-CSS/mg111.css"><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.16/css/mg2.css"><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.11/css/styless.css"><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.11/css/styles.css"><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.11/css/font.css"><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.15/css/font2.css"><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.12/css/swiper/swiper.min.css" media="print" onload='this.media="all"'><link rel="stylesheet" href="https://npm.elemecdn.com/webxc@1.0.12/css/swiper/swiperstyle.css" media="print" onload='this.media="all"'><meta name="generator" content="Hexo 6.3.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg" onerror='onerror=null,src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="avatar"></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">95</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">25</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">25</div></a></div><hr><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw iconfont icon-shouye"></i> <span>首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw iconfont icon-shijian"></i> <span>时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw iconfont icon-biaoqian"></i> <span>标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw iconfont icon-fenlei"></i> <span>分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw iconfont icon-lianxiwomen"></i> <span>友联</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw iconfont icon-iconzhengli-"></i> <span>关于</span></a></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);"><i class="fa-fw iconfont icon-a-wangzhanchaojilianjiehulianwang"></i> <span>推荐</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" target="_blank" rel="noopener" href="http://www.inode.club/"><i class="fa-fw fa-sharp fa-solid fa-square-rss"></i> <span>程序员指南</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="http://ife.baidu.com/"><i class="fa-fw fa-brands fa-vuejs"></i> <span>前端技术学园</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.yuque.com/tademanong/ag7q4n"><i class="fa-fw fa-solid fa-users"></i> <span>前端技术圈</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.code-nav.cn/"><i class="fa-fw fa-solid fa-shop"></i> <span>编程导航</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://q.shanyue.tech/"><i class="fa-fw fa-brands fa-square-js"></i> <span>每日一题</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://fanyouf.gitee.io/u1word/#/h5"><i class="fa-fw fa-solid fa-headphones"></i> <span>前端必会单词</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://site.51git.cn/render/gonav/4.html"><i class="fa-fw iconfont icon-wangzhandingzhi"></i> <span>网址导航</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.webxc.eu.org/music/"><i class="fa-fw iconfont icon-musical-note"></i> <span>音乐解锁</span></a></li></ul></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image:url('https://cdn1.tianli0.top/gh/web-xc/iMG/postss/ajax.webp')"><nav id="nav"><span id="blog_name"><div class="back-home-button" tabindex="-1"><i class="back-home-button-icon fas fa-grip-vertical"></i><div class="back-menu-list-groups"><div class="back-menu-list-group"><div class="back-menu-list-title">项目</div><div class="back-menu-list"><a class="back-menu-item" href="/" title="前往博客主页" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">主站</span></a><a class="back-menu-item" href="https://e.webxc.eu.org/" rel="external nofollow" title="前往学习笔记" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">学习笔记</span></a><a class="back-menu-item" href="https://v.webxc.eu.org/" rel="external nofollow" title="VuePress学习文档" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">VuePress文档</span></a><a class="back-menu-item" href="https://b.webxc.eu.org/" rel="external nofollow" title="旧站Hexo" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">旧站Hexo</span></a><a class="back-menu-item" href="https://gridea.webxc.eu.org/" rel="external nofollow" title="Gridea笔记" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">Gridea笔记</span></a><a class="back-menu-item" href="https://c.webxc.eu.org/" rel="external nofollow" title="魔改Hexo" target="_blank" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">魔改Hexo</span></a></div></div><div class="back-menu-list-group"><div class="back-menu-list-title">博客镜像</div><div class="back-menu-list"><a class="back-menu-item" href="https://blog.webxc.eu.org/" title="Vercel镜像" target="_blank" rel="noopener nofollow" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">Vercel镜像</span></a><a class="back-menu-item" href="https://webxc.tk/" title="Netlify镜像" target="_blank" rel="noopener nofollow" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">Netlify镜像</span></a><a class="back-menu-item" href="https://web-xc.gitee.io/" title="Gitee镜像" target="_blank" rel="noopener nofollow" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">Gitee镜像</span></a><a class="back-menu-item" href="https://cf.webxc.eu.org/" title="Cloudflare镜像" target="_blank" rel="noopener nofollow" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">Cloudflare镜像</span></a><a class="back-menu-item" href="https://render.webxc.eu.org/" title="Render镜像" target="_blank" rel="noopener nofollow" one-link-mark="yes"><img class="back-menu-item-icon" src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg"><span class="back-menu-item-text">Render镜像</span></a></div></div></div></div><a id="site-name" href="/"><div class="title">XC's Blog</div><i class="fa-solid fa-house"></i></a></span><div class="mask-name-container"><center id="name-container"><a id="page-name" href="javascript:btf.scrollToDest(0, 500)">PAGE_NAME</a></center></div><div id="menus"><div class="nav-button" id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i> <span>搜索</span></a></div><div class="nav-button" id="darkmode_navswitch"><a class="darkmode_switchbutton" type="button" title="浅色和深色模式转换" onclick="switchDarkMode()"><i class="fas fa-adjust"></i></a></div><div class="nav-button" id="nav-totop"><a class="totopbtn"><i class="fas fa-arrow-up"></i><span id="percent" onclick="btf.scrollToDest(0,500)">0</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw iconfont icon-shouye"></i> <span>首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw iconfont icon-shijian"></i> <span>时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw iconfont icon-biaoqian"></i> <span>标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw iconfont icon-fenlei"></i> <span>分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw iconfont icon-lianxiwomen"></i> <span>友联</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw iconfont icon-iconzhengli-"></i> <span>关于</span></a></div><div class="menus_item"><a class="site-page group hide" href="javascript:void(0);"><i class="fa-fw iconfont icon-a-wangzhanchaojilianjiehulianwang"></i> <span>推荐</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" target="_blank" rel="noopener" href="http://www.inode.club/"><i class="fa-fw fa-sharp fa-solid fa-square-rss"></i> <span>程序员指南</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="http://ife.baidu.com/"><i class="fa-fw fa-brands fa-vuejs"></i> <span>前端技术学园</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.yuque.com/tademanong/ag7q4n"><i class="fa-fw fa-solid fa-users"></i> <span>前端技术圈</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.code-nav.cn/"><i class="fa-fw fa-solid fa-shop"></i> <span>编程导航</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://q.shanyue.tech/"><i class="fa-fw fa-brands fa-square-js"></i> <span>每日一题</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://fanyouf.gitee.io/u1word/#/h5"><i class="fa-fw fa-solid fa-headphones"></i> <span>前端必会单词</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://site.51git.cn/render/gonav/4.html"><i class="fa-fw iconfont icon-wangzhandingzhi"></i> <span>网址导航</span></a></li><li><a class="site-page child" target="_blank" rel="noopener" href="https://www.webxc.eu.org/music/"><i class="fa-fw iconfont icon-musical-note"></i> <span>音乐解锁</span></a></li></ul></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Ajax第一天</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-05-31T23:30:00.000Z" title="发表于 2023-05-31 23:30:00">2023-05-31</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-08-30T18:00:49.013Z" title="更新于 2023-08-30 18:00:49">2023-08-30</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/Ajax%E7%AC%94%E8%AE%B0/">Ajax笔记</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span data-flag-title="Ajax第一天"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="twikoo_visitors"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h3 id="Ajax第一天-–-ajax概念-–-axios的使用-–-HTTP协议"><a href="#Ajax第一天-–-ajax概念-–-axios的使用-–-HTTP协议" class="headerlink" title="Ajax第一天 – ajax概念 – axios的使用 – HTTP协议"></a>Ajax第一天 – ajax概念 – axios的使用 – HTTP协议</h3><h2 id="知识点自测"><a href="#知识点自测" class="headerlink" title="知识点自测"></a>知识点自测</h2><ol><li><p>如下对象取值的方式哪个正确?</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> obj = &#123;</span><br><span class="line">    <span class="attr">name</span>: <span class="string">&#x27;黑马&#x27;</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p>A: obj.a</p><p>B: obj()a</p><details><summary>答案</summary><ul><li>A选项正确</li></ul></details></li><li><p>哪个赋值会让浏览器解析成标签显示?</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> ul = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;#ul&#x27;</span>)</span><br><span class="line"><span class="keyword">let</span> str = <span class="string">`&lt;span&gt;我是span标签&lt;/span&gt;`</span></span><br></pre></td></tr></table></figure><p>A: ul.innerText &#x3D; str</p><p>B: ul.innerHTML &#x3D; str</p><details><summary>答案</summary><ul><li>选择B, innerText会把字符串当做普通文本现在在ul标签之间, innerHTML会试着把字符串解析成标签, 如果是普通文本则显示普通文本字符串</li></ul></details></li><li><p>哪个是获取输入框值的方式?</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> theInput = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;#input&#x27;</span>)</span><br></pre></td></tr></table></figure><p>A: theInput.innerHTML</p><p>B: theInput.value</p><details><summary>答案</summary><ul><li>答案是B, 表单标签设置或获取值用value属性, 其他标签用innerHTML/innerText, 进行设置/获取</li></ul></details></li><li><p>哪个是用于获取标签内容?</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> theP = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;#p&#x27;</span>)</span><br></pre></td></tr></table></figure><p>A: theP.innerHTML &#x3D; ‘内容’</p><p>B: theP.innerHTML</p><details><summary>答案</summary><ul><li>答案是B, 单独出现是获取值在原地, 如果看到=这个符号, 是把右侧的值赋予给左侧的属性, 影响标签展示效果</li></ul></details></li><li><p>哪个是数组的映射方法？</p><p>A: arr.forEach</p><p>B: arr.map</p><details><summary>答案</summary><ul><li>答案是B</li></ul></details></li><li><p>数组转字符串并指定拼接符的是哪个?</p><p>A: arr.join()</p><p>B: arr.split()</p><details><summary>答案</summary><ul><li>答案是A</li></ul></details></li><li><p>函数传参的方式哪个是正确的？</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">showAlert</span>(<span class="params">msg, className</span>) &#123;&#125;</span><br></pre></td></tr></table></figure><p>A：showAlert(‘消息’, ‘类名’)</p><p>B：showAlert()</p><details><summary>答案</summary><ul><li>答案是A</li></ul></details></li><li><p>以下哪套代码可以实现对象属性的简写？</p><p>A：</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> username = <span class="string">&#x27;老李&#x27;</span></span><br><span class="line"><span class="keyword">let</span> obj = &#123;</span><br><span class="line">  <span class="attr">username</span>: username</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p>B：</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> user = <span class="string">&#x27;老李&#x27;</span></span><br><span class="line"><span class="keyword">let</span> obj = &#123;</span><br><span class="line">  <span class="attr">username</span>: user</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><details><summary>答案</summary><ul><li>答案是A</li></ul></details></li><li><p>以下代码的值是多少？</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> age = <span class="number">10</span></span><br><span class="line"><span class="keyword">const</span> result = age &gt; <span class="number">18</span> ? <span class="string">&#x27;成年了&#x27;</span> : <span class="string">&#x27;未成年&#x27;</span></span><br></pre></td></tr></table></figure><p>A：‘成年了’</p><p>B：‘未成年’</p><details><summary>答案</summary><ul><li>答案是B</li></ul></details></li><li><p>以下哪个方法可以添加一个额外类名？</p><p>A：标签对象.classList.add()</p><p>B：标签对象.classList.contains()</p><details><summary>答案</summary><ul><li>答案是A</li></ul></details></li></ol><h2 id="目录"><a href="#目录" class="headerlink" title="目录"></a>目录</h2><ul><li>AJAX 概念和 axios 使用</li><li>认识 URL</li><li>URL 查询参数</li><li>常用请求方法和数据提交</li><li>HTTP协议-报文</li><li>接口文档</li><li>案例 - 用户登录</li><li>form-serialize 插件</li></ul><h2 id="学习目标"><a href="#学习目标" class="headerlink" title="学习目标"></a>学习目标</h2><ol><li>掌握 axios 相关参数，从服务器获取并解析展示数据</li><li>掌握接口文档的查看和使用</li><li>掌握在浏览器的 network 面板中查看请求和响应的内容</li><li>了解请求和响应报文的组成部分</li></ol><h2 id="01-AJAX-概念和-axios-使用"><a href="#01-AJAX-概念和-axios-使用" class="headerlink" title="01.AJAX 概念和 axios 使用"></a>01.AJAX 概念和 axios 使用</h2><h3 id="目标"><a href="#目标" class="headerlink" title="目标"></a>目标</h3><ul><li>了解 AJAX 概念并掌握 axios 库基本使用</li></ul><h3 id="讲解"><a href="#讲解" class="headerlink" title="讲解"></a>讲解</h3><ol><li><p>什么是 AJAX ? <a target="_blank" rel="noopener" href="https://developer.mozilla.org/zh-CN/docs/Web/Guide/AJAX/Getting_Started">mdn</a></p><ul><li>使用浏览器的 XMLHttpRequest 对象 与服务器通信</li></ul></li><li><p>什么是服务器？</p><ul><li>可以暂时理解为提供数据的一台电脑</li></ul></li><li><p>为何学 AJAX ?</p><ul><li>以前我们的数据都是写在代码里固定的, 无法随时变化</li><li>现在我们的数据可以从服务器上进行获取，让数据变活</li></ul></li><li><p>怎么学 AJAX ?</p><ul><li>这里使用一个第三方库叫 axios, 后续在学习 XMLHttpRequest 对象了解 AJAX 底层原理</li><li>因为 axios 库语法简单，让我们有更多精力关注在与服务器通信上，而且后续 Vue，React 学习中，也使用 axios 库与服务器通信</li></ul></li><li><p>接下来讲解 axios 语法</p><ol><li><p>引入 axios.js 文件到自己的网页中</p><blockquote><p>axios.js文件链接: <a target="_blank" rel="noopener" href="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js">https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js</a></p></blockquote></li><li><p>明确axios函数的使用语法</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="title function_">axios</span>(&#123;</span><br><span class="line">  <span class="attr">url</span>: <span class="string">&#x27;目标资源地址&#x27;</span></span><br><span class="line">&#125;).<span class="title function_">then</span>(<span class="function">(<span class="params">result</span>) =&gt;</span> &#123;</span><br><span class="line">  <span class="comment">// 对服务器返回的数据做后续处理</span></span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure><blockquote><p>注意：请求的 url 地址, 就是标记资源的网址</p><p>注意：then 方法这里先体验使用，由来后续会讲到</p></blockquote></li></ol></li><li><p>用一个需求来体验 axios 语法的使用，从服务器获取省份列表数据，展示到页面上</p><blockquote><p>获取省份列表数据 - 目标资源地址：<a target="_blank" rel="noopener" href="http://hmajax.itheima.net/api/province">http://hmajax.itheima.net/api/province</a></p></blockquote><ul><li><p>完成效果：</p><p><img src="" data-lazy-src="https://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/hm8.1ajax/image-20230220113157010.png" alt="image-20230220113157010"></p></li><li><p>对应代码</p><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">http-equiv</span>=<span class="string">&quot;X-UA-Compatible&quot;</span> <span class="attr">content</span>=<span class="string">&quot;IE=edge&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">&quot;viewport&quot;</span> <span class="attr">content</span>=<span class="string">&quot;width=device-width, initial-scale=1.0&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">title</span>&gt;</span>AJAX概念和axios使用<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">  <span class="comment">&lt;!--</span></span><br><span class="line"><span class="comment">    axios库地址：https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js</span></span><br><span class="line"><span class="comment">    省份数据地址：http://hmajax.itheima.net/api/province</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">    目标: 使用axios库, 获取省份列表数据, 展示到页面上</span></span><br><span class="line"><span class="comment">    1. 引入axios库</span></span><br><span class="line"><span class="comment">  --&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">p</span> <span class="attr">class</span>=<span class="string">&quot;my-p&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">    <span class="comment">// 2. 使用axios函数</span></span></span><br><span class="line"><span class="language-javascript">    <span class="title function_">axios</span>(&#123;</span></span><br><span class="line"><span class="language-javascript">      <span class="attr">url</span>: <span class="string">&#x27;http://hmajax.itheima.net/api/province&#x27;</span></span></span><br><span class="line"><span class="language-javascript">    &#125;).<span class="title function_">then</span>(<span class="function"><span class="params">result</span> =&gt;</span> &#123;</span></span><br><span class="line"><span class="language-javascript">      <span class="variable language_">console</span>.<span class="title function_">log</span>(result)</span></span><br><span class="line"><span class="language-javascript">      <span class="comment">// 好习惯：多打印，确认属性名</span></span></span><br><span class="line"><span class="language-javascript">      <span class="variable language_">console</span>.<span class="title function_">log</span>(result.<span class="property">data</span>.<span class="property">list</span>)</span></span><br><span class="line"><span class="language-javascript">      <span class="variable language_">console</span>.<span class="title function_">log</span>(result.<span class="property">data</span>.<span class="property">list</span>.<span class="title function_">join</span>(<span class="string">&#x27;&lt;br&gt;&#x27;</span>))</span></span><br><span class="line"><span class="language-javascript">      <span class="comment">// 把准备好省份列表，插入到页面</span></span></span><br><span class="line"><span class="language-javascript">      <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;.my-p&#x27;</span>).<span class="property">innerHTML</span> = result.<span class="property">data</span>.<span class="property">list</span>.<span class="title function_">join</span>(<span class="string">&#x27;&lt;br&gt;&#x27;</span>) </span></span><br><span class="line"><span class="language-javascript">    &#125;)</span></span><br><span class="line"><span class="language-javascript">  </span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure></li></ul></li></ol><h3 id="小结"><a href="#小结" class="headerlink" title="小结"></a>小结</h3><ol><li><p>AJAX 有什么用？</p><details><summary>答案</summary><ul><li>浏览器和服务器之间通信，动态数据交互</li></ul></details></li><li><p>AJAX 如何学：</p><details><summary>答案</summary><ul><li>先掌握 axios 库使用，再了解 XMLHttpRequest 原理</li></ul></details></li><li><p>这一节 axios 体验步骤（语法）？</p><details><summary>答案</summary><ul><li>引入 axios 库，使用 axios 相关语法</li></ul></details></li></ol><h2 id="02-认识-URL"><a href="#02-认识-URL" class="headerlink" title="02.认识 URL"></a>02.认识 URL</h2><h3 id="目标-1"><a href="#目标-1" class="headerlink" title="目标"></a>目标</h3><ul><li>了解 URL 的组成和作用</li></ul><h3 id="讲解-1"><a href="#讲解-1" class="headerlink" title="讲解"></a>讲解</h3><ol><li><p>为什么要认识 URL ? <a target="_blank" rel="noopener" href="https://developer.mozilla.org/zh-CN/docs/Web/Guide/AJAX/Getting_Started">mdn</a></p><ul><li>虽然是后端给我的一个地址，但是哪部分标记的是服务器，哪部分标记的是资源呢？所以为了和服务器有效沟通我们要认识一下</li></ul></li><li><p>什么是 URL ？</p><ul><li>统一资源定位符，简称网址，用于定位网络中的资源</li><li>资源：网页，图片，数据，视频，音频等等</li></ul></li><li><p>URL 的组成?</p><ul><li>协议，域名，资源路径（URL 组成有很多部分，我们先掌握这3个重要的部分即可）</li></ul></li><li><p>什么是 http 协议 ?</p><ul><li>叫超文本传输协议，规定了浏览器和服务器传递数据的格式（而格式具体有哪些稍后我们就会学到）</li></ul></li><li><p>什么是域名 ?</p><ul><li>标记服务器在互联网当中的方位，网络中有很多服务器，你想访问哪一台，就需要知道它的域名才可以</li></ul></li><li><p>什么是资源路径 ?</p><ul><li>一个服务器内有多个资源，用于标识你要访问的资源具体的位置</li></ul></li><li><p>接下来做个需求，访问新闻列表的 URL 网址，打印新闻数据</p><ul><li>效果图如下：</li></ul><p><img src="" data-lazy-src="https://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/hm8.1ajax/image-20230220122455915.png" alt="image-20230220122455915"></p><blockquote><p>新闻列表数据 URL 网址：<a target="_blank" rel="noopener" href="http://hmajax.itheima.net/api/news">http://hmajax.itheima.net/api/news</a></p></blockquote><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="title function_">axios</span>(&#123;</span><br><span class="line">  <span class="attr">url</span>: <span class="string">&#x27;http://hmajax.itheima.net/api/news&#x27;</span></span><br><span class="line">&#125;).<span class="title function_">then</span>(<span class="function"><span class="params">result</span> =&gt;</span> &#123;</span><br><span class="line">  <span class="variable language_">console</span>.<span class="title function_">log</span>(result)</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure><blockquote><p>url解释：从黑马服务器使用http协议，访问&#x2F;api&#x2F;news路径下的新闻列表资源</p></blockquote></li></ol><h3 id="小结-1"><a href="#小结-1" class="headerlink" title="小结"></a>小结</h3><ol><li><p>URL 是什么？</p><details><summary>答案</summary><ul><li>统一资源定位符，网址，用于访问服务器上资源</li></ul></details></li><li><p>请解释这个 URL，每个部分作用？</p><p><a target="_blank" rel="noopener" href="http://hmajax.itheima.net/api/news">http://hmajax.itheima.net/api/news</a></p><details><summary>答案</summary><ul><li>协议://域名/资源路径</li></ul></details></li></ol><h2 id="03-URL-查询参数"><a href="#03-URL-查询参数" class="headerlink" title="03.URL 查询参数"></a>03.URL 查询参数</h2><h3 id="目标-2"><a href="#目标-2" class="headerlink" title="目标"></a>目标</h3><ul><li>掌握-通过URL传递查询参数，获取匹配的数据</li></ul><h3 id="讲解-2"><a href="#讲解-2" class="headerlink" title="讲解"></a>讲解</h3><ol><li><p>什么是查询参数 ?</p><ul><li>携带给服务器额外信息，让服务器返回我想要的某一部分数据而不是全部数据</li><li>举例：查询河北省下属的城市列表，需要先把河北省传递给服务器</li></ul></li><li><p>查询参数的语法 ？</p><ul><li>在 url 网址后面用?拼接，格式参数名&#x3D;值&amp;参数名&#x3D;值的查询参数字符串</li><li>参数名一般是后端规定的，值前端看情况传递即可</li></ul></li><li><p>axios 如何携带查询参数?</p><ul><li><p>使用 params 选项即可、</p><p><img src="" data-lazy-src="https://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/hm8.1ajax/image-20230220124958792.png" alt="image-20230220124958792"></p><blockquote><p>查询城市列表的 url地址：<a target="_blank" rel="noopener" href="http://hmajax.itheima.net/api/city?pname=%E6%B2%B3%E5%8C%97%E7%9C%81">http://hmajax.itheima.net/api/city</a></p><p>参数名：pname （值要携带省份名字）</p></blockquote></li></ul></li><li><p>需求：获取指定省份名字下属的城市列表，展示到页面</p><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">http-equiv</span>=<span class="string">&quot;X-UA-Compatible&quot;</span> <span class="attr">content</span>=<span class="string">&quot;IE=edge&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">&quot;viewport&quot;</span> <span class="attr">content</span>=<span class="string">&quot;width=device-width, initial-scale=1.0&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">title</span>&gt;</span>查询参数<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">  <span class="comment">&lt;!-- </span></span><br><span class="line"><span class="comment">    城市列表: http://hmajax.itheima.net/api/city</span></span><br><span class="line"><span class="comment">    参数名: pname</span></span><br><span class="line"><span class="comment">    值: 省份名字</span></span><br><span class="line"><span class="comment">  --&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">p</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">    <span class="title function_">axios</span>(&#123;</span></span><br><span class="line"><span class="language-javascript">      <span class="attr">url</span>: <span class="string">&#x27;http://hmajax.itheima.net/api/city&#x27;</span>,</span></span><br><span class="line"><span class="language-javascript">      <span class="comment">// 查询参数</span></span></span><br><span class="line"><span class="language-javascript">      <span class="attr">params</span>: &#123;</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">pname</span>: <span class="string">&#x27;辽宁省&#x27;</span></span></span><br><span class="line"><span class="language-javascript">      &#125;</span></span><br><span class="line"><span class="language-javascript">    &#125;).<span class="title function_">then</span>(<span class="function"><span class="params">result</span> =&gt;</span> &#123;</span></span><br><span class="line"><span class="language-javascript">      <span class="variable language_">console</span>.<span class="title function_">log</span>(result.<span class="property">data</span>.<span class="property">list</span>)</span></span><br><span class="line"><span class="language-javascript">      <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;p&#x27;</span>).<span class="property">innerHTML</span> = result.<span class="property">data</span>.<span class="property">list</span>.<span class="title function_">join</span>(<span class="string">&#x27;&lt;br&gt;&#x27;</span>)</span></span><br><span class="line"><span class="language-javascript">    &#125;)</span></span><br><span class="line"><span class="language-javascript">  </span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure></li></ol><h3 id="小结-2"><a href="#小结-2" class="headerlink" title="小结"></a>小结</h3><ol><li><p>URL 查询参数有什么用？</p><details><summary>答案</summary><ul><li>浏览器提供给服务器额外信息，获取对应的数据</li></ul></details></li><li><p>axios 要如何携带查询参数？</p><details><summary>答案</summary><ul><li>使用 params 选项，携带参数名和值在对象结构中</li></ul></details></li></ol><h2 id="04-案例-查询-地区列表"><a href="#04-案例-查询-地区列表" class="headerlink" title="04.案例-查询-地区列表"></a>04.案例-查询-地区列表</h2><h3 id="目标-3"><a href="#目标-3" class="headerlink" title="目标"></a>目标</h3><ul><li>巩固查询参数的使用，并查看多对查询参数如何传递</li></ul><h3 id="讲解-3"><a href="#讲解-3" class="headerlink" title="讲解"></a>讲解</h3><ol><li><p>需求：根据输入的省份名字和城市名字，查询下属地区列表</p><ul><li><p>完成效果如下：</p><p><img src="" data-lazy-src="https://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/hm8.1ajax/image-20230220125428695.png" alt="image-20230220125428695"></p></li><li><p>相关参数</p><blockquote><p>查询地区: <a target="_blank" rel="noopener" href="http://hmajax.itheima.net/api/area">http://hmajax.itheima.net/api/area</a></p><p>参数名：</p><p>pname：省份名字</p><p>cname：城市名字</p></blockquote></li></ul></li><li><p>正确代码如下：</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">      获取地区列表: http://hmajax.itheima.net/api/area</span></span><br><span class="line"><span class="comment">      查询参数:</span></span><br><span class="line"><span class="comment">        pname: 省份或直辖市名字</span></span><br><span class="line"><span class="comment">        cname: 城市名字</span></span><br><span class="line"><span class="comment">    */</span></span><br><span class="line"><span class="comment">// 目标: 根据省份和城市名字, 查询地区列表</span></span><br><span class="line"><span class="comment">// 1. 查询按钮-点击事件</span></span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;.sel-btn&#x27;</span>).<span class="title function_">addEventListener</span>(<span class="string">&#x27;click&#x27;</span>, <span class="function">() =&gt;</span> &#123;</span><br><span class="line">    <span class="comment">// 2. 获取省份和城市名字</span></span><br><span class="line">    <span class="keyword">let</span> pname = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;.province&#x27;</span>).<span class="property">value</span></span><br><span class="line">    <span class="keyword">let</span> cname = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;.city&#x27;</span>).<span class="property">value</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">// 3. 基于axios请求地区列表数据</span></span><br><span class="line">    <span class="title function_">axios</span>(&#123;</span><br><span class="line">        <span class="attr">url</span>: <span class="string">&#x27;http://hmajax.itheima.net/api/area&#x27;</span>,</span><br><span class="line">        <span class="attr">params</span>: &#123;</span><br><span class="line">            pname,</span><br><span class="line">            cname</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;).<span class="title function_">then</span>(<span class="function"><span class="params">result</span> =&gt;</span> &#123;</span><br><span class="line">        <span class="comment">// console.log(result)</span></span><br><span class="line">        <span class="comment">// 4. 把数据转li标签插入到页面上</span></span><br><span class="line">        <span class="keyword">let</span> list = result.<span class="property">data</span>.<span class="property">list</span></span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(list)</span><br><span class="line">        <span class="keyword">let</span> theLi = list.<span class="title function_">map</span>(<span class="function"><span class="params">areaName</span> =&gt;</span> <span class="string">`&lt;li class=&quot;list-group-item&quot;&gt;<span class="subst">$&#123;areaName&#125;</span>&lt;/li&gt;`</span>).<span class="title function_">join</span>(<span class="string">&#x27;&#x27;</span>)</span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(theLi)</span><br><span class="line">        <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;.list-group&#x27;</span>).<span class="property">innerHTML</span> = theLi</span><br><span class="line">    &#125;)</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure></li></ol><h3 id="小结-3"><a href="#小结-3" class="headerlink" title="小结"></a>小结</h3><ol><li><p>ES6 对象属性和值简写的前提是什么？</p><details><summary>答案</summary><ul><li>当属性名和value位置变量名同名即可简写</li></ul></details></li></ol><h2 id="05-常用请求方法和数据提交"><a href="#05-常用请求方法和数据提交" class="headerlink" title="05.常用请求方法和数据提交"></a>05.常用请求方法和数据提交</h2><h3 id="目标-4"><a href="#目标-4" class="headerlink" title="目标"></a>目标</h3><ul><li>掌握如何向服务器提交数据，而不单单是获取数据</li></ul><h3 id="讲解-4"><a href="#讲解-4" class="headerlink" title="讲解"></a>讲解</h3><ol><li><p>想要提交数据，先来了什么是请求方法</p><ul><li><p>请求方法是一些固定单词的英文，例如：GET，POST，PUT，DELETE，PATCH（这些都是http协议规定的），每个单词对应一种对服务器资源要执行的操作</p><p><img src="" data-lazy-src="https://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/hm8.1ajax/image-20230220130833363.png" alt="image-20230220130833363"></p></li><li><p>前面我们获取数据其实用的就是GET请求方法，但是axios内部设置了默认请求方法就是GET，我们就没有写</p></li><li><p>但是提交数据需要使用POST请求方法</p></li></ul></li><li><p>什么时候进行数据提交呢？</p><ul><li>例如：多端要查看同一份订单数据，或者使用同一个账号进行登录，那订单&#x2F;用户名+密码，就需要保存在服务器上，随时随地进行访问</li></ul></li><li><p>axios 如何提交数据到服务器呢？</p><ul><li><p>需要学习，method 和 data 这2个新的选项了（大家不用担心，这2个学完，axios常用的选项就都学完了）</p><p><img src="" data-lazy-src="https://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/hm8.1ajax/image-20230220131058168.png" alt="image-20230220131058168"></p></li></ul></li><li><p>需求：注册账号，提交用户名和密码到服务器保存</p><blockquote><p>注册用户 URL 网址：<a target="_blank" rel="noopener" href="http://hmajax.itheima.net/api/register">http://hmajax.itheima.net/api/register</a></p><p>请求方法：POST</p><p>参数名：</p><p>username：用户名（要求中英文和数字组成，最少8位）</p><p>password：密码（最少6位）</p></blockquote></li></ol><h3 id="小结-4"><a href="#小结-4" class="headerlink" title="小结"></a>小结</h3><ol><li><p>请求方法最常用的是哪2个，分别有什么作用？</p><details><summary>答案</summary><ul><li>POST 提交数据，GET 查询数据</li></ul></details></li><li><p>axios 的核心配置项？</p><details><summary>答案</summary><ul><li>url：目标资源地址，method：请求方法，params：查询参数，data：提交的数据</li></ul></details></li></ol><h2 id="06-axios-错误处理"><a href="#06-axios-错误处理" class="headerlink" title="06.axios 错误处理"></a>06.axios 错误处理</h2><h3 id="目标-5"><a href="#目标-5" class="headerlink" title="目标"></a>目标</h3><ul><li>掌握接收 axios 响应错误信息的处理语法</li></ul><h3 id="讲解-5"><a href="#讲解-5" class="headerlink" title="讲解"></a>讲解</h3><ol><li><p>如果注册相同的用户名，则会遇到注册失败的请求，也就是 axios 请求响应失败了，你会在控制台看到如图的错误：</p><p><img src="" data-lazy-src="https://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/hm8.1ajax/image-20230220131753051.png" alt="image-20230220131753051"></p></li><li><p>在 axios 语法中要如何处理呢？</p><ul><li>因为，普通用户不会去控制台里看错误信息，我们要编写代码拿到错误并展示给用户在页面上</li></ul></li><li><p>使用 axios 的 catch 方法，捕获这次请求响应的错误并做后续处理，语法如下：</p><p><img src="" data-lazy-src="https://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/hm8.1ajax/image-20230220131911928.png" alt="image-20230220131911928"></p></li><li><p>对应代码</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;.btn&#x27;</span>).<span class="title function_">addEventListener</span>(<span class="string">&#x27;click&#x27;</span>, <span class="function">() =&gt;</span> &#123;</span><br><span class="line">    <span class="title function_">axios</span>(&#123;</span><br><span class="line">      <span class="attr">url</span>: <span class="string">&#x27;http://hmajax.itheima.net/api/register&#x27;</span>,</span><br><span class="line">      <span class="attr">method</span>: <span class="string">&#x27;post&#x27;</span>,</span><br><span class="line">      <span class="attr">data</span>: &#123;</span><br><span class="line">        <span class="attr">username</span>: <span class="string">&#x27;itheima007&#x27;</span>,</span><br><span class="line">        <span class="attr">password</span>: <span class="string">&#x27;7654321&#x27;</span></span><br><span class="line">      &#125;</span><br><span class="line">    &#125;).<span class="title function_">then</span>(<span class="function"><span class="params">result</span> =&gt;</span> &#123;</span><br><span class="line">      <span class="comment">// 成功</span></span><br><span class="line">      <span class="variable language_">console</span>.<span class="title function_">log</span>(result)</span><br><span class="line">    &#125;).<span class="title function_">catch</span>(<span class="function"><span class="params">error</span> =&gt;</span> &#123;</span><br><span class="line">      <span class="comment">// 失败</span></span><br><span class="line">      <span class="comment">// 处理错误信息</span></span><br><span class="line">      <span class="variable language_">console</span>.<span class="title function_">log</span>(error)</span><br><span class="line">      <span class="variable language_">console</span>.<span class="title function_">log</span>(error.<span class="property">response</span>.<span class="property">data</span>.<span class="property">message</span>)</span><br><span class="line">      <span class="title function_">alert</span>(error.<span class="property">response</span>.<span class="property">data</span>.<span class="property">message</span>)</span><br><span class="line">    &#125;)</span><br><span class="line">   &#125;)</span><br></pre></td></tr></table></figure></li></ol><h3 id="小结-5"><a href="#小结-5" class="headerlink" title="小结"></a>小结</h3><ol><li><p>axios 如何拿到请求响应失败的信息？</p><details><summary>答案</summary><ul><li>通过 axios 函数调用后，在后面接着调用 .catch 方法捕获</li></ul></details></li></ol><h2 id="07-HTTP-协议-请求报文"><a href="#07-HTTP-协议-请求报文" class="headerlink" title="07.HTTP 协议-请求报文"></a>07.HTTP 协议-请求报文</h2><h3 id="目标-6"><a href="#目标-6" class="headerlink" title="目标"></a>目标</h3><ul><li>了解 HTTP 协议中，请求报文的组成和作用</li></ul><h3 id="讲解-6"><a href="#讲解-6" class="headerlink" title="讲解"></a>讲解</h3><ol><li><p>首先，HTTP 协议规定了浏览器和服务器返回内容的格式</p></li><li><p>请求报文：是浏览器按照协议规定发送给服务器的内容，例如刚刚注册用户时，发起的请求报文：</p><p><img src="" data-lazy-src="https://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/hm8.1ajax/image-20230220132229960.png" alt="image-20230220132229960"></p></li><li><p>这里的格式包含：</p><ul><li>请求行：请求方法，URL，协议</li><li>请求头：以键值对的格式携带的附加信息，比如：Content-Type（指定了本次传递的内容类型）</li><li>空行：分割请求头，空行之后的是发送给服务器的资源</li><li>请求体：发送的资源</li></ul></li><li><p>我们切换到浏览器中，来看看刚才注册用户发送的这个请求报文以及内容去哪里查看呢</p></li></ol><h3 id="小结-6"><a href="#小结-6" class="headerlink" title="小结"></a>小结</h3><ol><li><p>浏览器发送给服务器的内容叫做，请求报文</p></li><li><p>请求报文的组成是：</p><details><summary>答案</summary><ul><li>请求行，请求头，空行，请求体</li></ul></details></li><li><p>通过 Chrome 的网络面板如何查看请求体？</p><p><img src="" data-lazy-src="https://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/hm8.1ajax/image-20230220132617016.png" alt="image-20230220132617016"></p></li></ol><h2 id="08-请求报文-错误排查"><a href="#08-请求报文-错误排查" class="headerlink" title="08.请求报文-错误排查"></a>08.请求报文-错误排查</h2><h3 id="目标-7"><a href="#目标-7" class="headerlink" title="目标"></a>目标</h3><ul><li>了解学习了查看请求报文之后的作用，可以用来辅助错误排查</li></ul><h3 id="讲解-7"><a href="#讲解-7" class="headerlink" title="讲解"></a>讲解</h3><ol><li>学习了查看请求报文有什么用呢？<ul><li>可以用来确认我们代码发送的请求数据是否真的正确</li></ul></li><li>这里是我同桌的代码，它把登录也写完了，但是无法登录，我们来到模板代码中，找到运行后，在不逐行查看代码的情况下，帮他找找问题出现的原因</li><li>发现请求体数据有问题，往代码中定位，找到类名写错误了</li></ol><h3 id="小结-7"><a href="#小结-7" class="headerlink" title="小结"></a>小结</h3><ol><li><p>学会了查看请求报文，对实际开发有什么帮助呢？</p><details><summary>答案</summary><ul><li>可以快速确认我们发送的内容是否正确</li></ul></details></li></ol><h2 id="09-HTTP-协议-响应报文"><a href="#09-HTTP-协议-响应报文" class="headerlink" title="09.HTTP 协议-响应报文"></a>09.HTTP 协议-响应报文</h2><h3 id="目标-8"><a href="#目标-8" class="headerlink" title="目标"></a>目标</h3><ul><li>了解响应报文的组成</li></ul><h3 id="讲解-8"><a href="#讲解-8" class="headerlink" title="讲解"></a>讲解</h3><ol><li><p>响应报文：是服务器按照协议固定的格式，返回给浏览器的内容</p><p><img src="" data-lazy-src="https://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/hm8.1ajax/image-20230220133141151.png" alt="image-20230220133141151"></p></li><li><p>响应报文的组成：</p><ul><li>响应行（状态行）：协议，HTTP响应状态码，状态信息</li><li>响应头：以键值对的格式携带的附加信息，比如：Content-Type（告诉浏览器，本次返回的内容类型）</li><li>空行：分割响应头，控制之后的是服务器返回的资源</li><li>响应体：返回的资源</li></ul></li><li><p>HTTP 响应状态码：</p><ul><li><p>用来表明请求是否成功完成</p></li><li><p>例如：404（服务器找不到资源）</p><p><img src="" data-lazy-src="https://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/hm8.1ajax/image-20230220133344116.png" alt="image-20230220133344116"></p></li></ul></li></ol><h3 id="小结-8"><a href="#小结-8" class="headerlink" title="小结"></a>小结</h3><ol><li><p>响应报文的组成？</p><details><summary>答案</summary><ul><li>响应行，响应头，空行，响应体</li></ul></details></li><li><p>HTTP 响应状态码是做什么的？</p><details><summary>答案</summary><ul><li>表明请求是否成功完成，2xx都是成功的</li></ul></details></li></ol><h2 id="10-接口文档"><a href="#10-接口文档" class="headerlink" title="10.接口文档"></a>10.接口文档</h2><h3 id="目标-9"><a href="#目标-9" class="headerlink" title="目标"></a>目标</h3><ul><li>掌握接口文档的使用，配合 axios 与服务器进行数据交互</li></ul><h3 id="讲解-9"><a href="#讲解-9" class="headerlink" title="讲解"></a>讲解</h3><ol><li>接口文档：描述接口的文章（一般是后端工程师，编写和提供）</li><li>接口：使用 AJAX 和 服务器通讯时，使用的 URL，请求方法，以及参数，例如：<a target="_blank" rel="noopener" href="https://www.apifox.cn/apidoc/project-1937884/doc-1695440">AJAX阶段接口文档</a></li><li>查看登录接口，并编写代码，完成一次登录的效果吧</li></ol><h3 id="小结-9"><a href="#小结-9" class="headerlink" title="小结"></a>小结</h3><ol><li><p>接口文档是什么？</p><details><summary>答案</summary><ul><li>由后端提供的描述接口的文章</li></ul></details></li><li><p>接口文档里包含什么？</p><details><summary>答案</summary><ul><li>请求的 URL 网址，请求方法，请求参数和说明</li></ul></details></li></ol><h2 id="11-案例-用户登录-主要业务"><a href="#11-案例-用户登录-主要业务" class="headerlink" title="11.案例-用户登录-主要业务"></a>11.案例-用户登录-主要业务</h2><h3 id="目标-10"><a href="#目标-10" class="headerlink" title="目标"></a>目标</h3><ul><li>尝试通过页面获取用户名和密码，进行登录</li></ul><h3 id="讲解-10"><a href="#讲解-10" class="headerlink" title="讲解"></a>讲解</h3><ol><li><p>先来到备课代码中，运行完成的页面，查看要完成的效果</p></li><li><p>分析实现的步骤</p><ol><li>点击登录，获取并判断用户名和长度</li><li>提交数据和服务器通信</li><li>提示信息，反馈给用户</li></ol></li><li><p>本视频先来完成前2步</p></li><li><p>编写代码，查看接口文档，填写相关信息，完成登录业务</p></li><li><p>代码细节：</p><ol><li>登录按钮-绑定点击事件</li><li>从页面输入框里，获取用户名和密码</li><li>判断长度是否符合要求</li><li>基于 axios 提交用户名和密码</li></ol></li></ol><h3 id="小结-10"><a href="#小结-10" class="headerlink" title="小结"></a>小结</h3><ol><li><p>总结下用户登录案例，本视频做的思路</p><details><summary>答案</summary><ul><li>1. 登录按钮-绑定点击事件 2. 从页面输入框里，获取用户名和密码 3. 判断长度是否符合要求 4. 基于 axios 提交用户名和密码</li></ul></details></li></ol><h2 id="12-案例-用户登录-提示信息"><a href="#12-案例-用户登录-提示信息" class="headerlink" title="12.案例-用户登录-提示信息"></a>12.案例-用户登录-提示信息</h2><h3 id="目标-11"><a href="#目标-11" class="headerlink" title="目标"></a>目标</h3><ul><li>根据准备好的提示标签和样式，给用户反馈提示</li></ul><h3 id="讲解-11"><a href="#讲解-11" class="headerlink" title="讲解"></a>讲解</h3><ol><li><p>先来到备课代码中，运行完成的页面，查看要完成的效果</p></li><li><p>使用提示框，反馈提示消息，因为有4处地方需要提示框，所以封装成函数</p><ol><li><p>获取提示框</p></li><li><p>封装提示框函数，重复调用，满足提示需求</p><p>功能：</p><ol><li>显示提示框</li><li>不同提示文字msg，和成功绿色失败红色isSuccess参数（true成功，false失败）</li><li>过2秒后，让提示框自动消失</li></ol></li></ol></li><li><p>对应提示框核心代码：</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 2.2 封装提示框函数，重复调用，满足提示需求</span></span><br><span class="line"><span class="comment">     * 功能：</span></span><br><span class="line"><span class="comment">     * 1. 显示提示框</span></span><br><span class="line"><span class="comment">     * 2. 不同提示文字msg，和成功绿色失败红色isSuccess（true成功，false失败）</span></span><br><span class="line"><span class="comment">     * 3. 过2秒后，让提示框自动消失</span></span><br><span class="line"><span class="comment">    */</span></span><br><span class="line">    <span class="keyword">function</span> <span class="title function_">alertFn</span>(<span class="params">msg, isSuccess</span>) &#123;</span><br><span class="line">      <span class="comment">// 1&gt; 显示提示框</span></span><br><span class="line">      myAlert.<span class="property">classList</span>.<span class="title function_">add</span>(<span class="string">&#x27;show&#x27;</span>)</span><br><span class="line"></span><br><span class="line">      <span class="comment">// 2&gt; 实现细节</span></span><br><span class="line">      myAlert.<span class="property">innerText</span> = msg</span><br><span class="line">      <span class="keyword">const</span> bgStyle = isSuccess ? <span class="string">&#x27;alert-success&#x27;</span> : <span class="string">&#x27;alert-danger&#x27;</span></span><br><span class="line">      myAlert.<span class="property">classList</span>.<span class="title function_">add</span>(bgStyle)</span><br><span class="line"></span><br><span class="line">      <span class="comment">// 3&gt; 过2秒隐藏</span></span><br><span class="line">      <span class="built_in">setTimeout</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">        myAlert.<span class="property">classList</span>.<span class="title function_">remove</span>(<span class="string">&#x27;show&#x27;</span>)</span><br><span class="line">        <span class="comment">// 提示：避免类名冲突，重置背景色</span></span><br><span class="line">        myAlert.<span class="property">classList</span>.<span class="title function_">remove</span>(bgStyle)</span><br><span class="line">      &#125;, <span class="number">2000</span>)</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure></li></ol><h3 id="小结-11"><a href="#小结-11" class="headerlink" title="小结"></a>小结</h3><ol><li><p>我们什么时候需要封装函数？</p><details><summary>答案</summary><ul><li>遇到相同逻辑，重复代码要复用的时候</li></ul></details></li><li><p>如何封装一个函数呢？</p><details><summary>答案</summary><ul><li>先明确要完成的需求，以及需要的参数，再来实现其中的细节，然后在需要的地方调用</li></ul></details></li><li><p>我们的提示框是如何控制出现&#x2F;隐藏的？</p><details><summary>答案</summary><ul><li>添加或移除显示的类名即可</li></ul></details></li></ol><h2 id="13-form-serialize-插件"><a href="#13-form-serialize-插件" class="headerlink" title="13.form-serialize 插件"></a>13.form-serialize 插件</h2><h3 id="目标-12"><a href="#目标-12" class="headerlink" title="目标"></a>目标</h3><ul><li>使用 form-serialize 插件，快速收集目标表单范围内表单元素的值</li></ul><h3 id="讲解-12"><a href="#讲解-12" class="headerlink" title="讲解"></a>讲解</h3><ol><li><p>我们前面收集表单元素的值，是一个个标签获取的</p></li><li><p>如果一套表单里有很多很多表单元素，如何一次性快速收集出来呢？</p></li><li><p>使用 form-serialize 插件提供的 serialize 函数就可以办到</p></li><li><p>form-serialize 插件语法：</p><ul><li>引入 form-serialize 插件到自己网页中</li><li>使用 serialize 函数<ul><li>参数1：要获取的 form 表单标签对象（要求表单元素需要有 name 属性-用来作为收集的数据中属性名）</li><li>参数2：配置对象<ul><li>hash：<ul><li>true - 收集出来的是一个 JS 对象结构</li><li>false - 收集出来的是一个查询字符串格式</li></ul></li><li>empty：<ul><li>true - 收集空值</li><li>false - 不收集空值</li></ul></li></ul></li></ul></li></ul></li><li><p>需求：收集登录表单里用户名和密码</p><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">http-equiv</span>=<span class="string">&quot;X-UA-Compatible&quot;</span> <span class="attr">content</span>=<span class="string">&quot;IE=edge&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">&quot;viewport&quot;</span> <span class="attr">content</span>=<span class="string">&quot;width=device-width, initial-scale=1.0&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">title</span>&gt;</span>form-serialize插件使用<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">form</span> <span class="attr">action</span>=<span class="string">&quot;javascript:;&quot;</span> <span class="attr">class</span>=<span class="string">&quot;example-form&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span> <span class="attr">name</span>=<span class="string">&quot;username&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span> <span class="attr">name</span>=<span class="string">&quot;password&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;button&quot;</span> <span class="attr">class</span>=<span class="string">&quot;btn&quot;</span> <span class="attr">value</span>=<span class="string">&quot;提交&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">form</span>&gt;</span></span><br><span class="line">  <span class="comment">&lt;!-- </span></span><br><span class="line"><span class="comment">    目标：在点击提交时，使用form-serialize插件，快速收集表单元素值</span></span><br><span class="line"><span class="comment">    1. 把插件引入到自己网页中</span></span><br><span class="line"><span class="comment">  --&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;./lib/form-serialize.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">    <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;.btn&#x27;</span>).<span class="title function_">addEventListener</span>(<span class="string">&#x27;click&#x27;</span>, <span class="function">() =&gt;</span> &#123;</span></span><br><span class="line"><span class="language-javascript">      <span class="comment">/**</span></span></span><br><span class="line"><span class="comment"><span class="language-javascript">       * 2. 使用serialize函数，快速收集表单元素的值</span></span></span><br><span class="line"><span class="comment"><span class="language-javascript">       * 参数1：要获取哪个表单的数据</span></span></span><br><span class="line"><span class="comment"><span class="language-javascript">       *  表单元素设置name属性，值会作为对象的属性名</span></span></span><br><span class="line"><span class="comment"><span class="language-javascript">       *  建议name属性的值，最好和接口文档参数名一致</span></span></span><br><span class="line"><span class="comment"><span class="language-javascript">       * 参数2：配置对象</span></span></span><br><span class="line"><span class="comment"><span class="language-javascript">       *  hash 设置获取数据结构</span></span></span><br><span class="line"><span class="comment"><span class="language-javascript">       *    - true：JS对象（推荐）一般请求体里提交给服务器</span></span></span><br><span class="line"><span class="comment"><span class="language-javascript">       *    - false: 查询字符串</span></span></span><br><span class="line"><span class="comment"><span class="language-javascript">       *  empty 设置是否获取空值</span></span></span><br><span class="line"><span class="comment"><span class="language-javascript">       *    - true: 获取空值（推荐）数据结构和标签结构一致</span></span></span><br><span class="line"><span class="comment"><span class="language-javascript">       *    - false：不获取空值</span></span></span><br><span class="line"><span class="comment"><span class="language-javascript">      */</span></span></span><br><span class="line"><span class="language-javascript">      <span class="keyword">const</span> form = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;.example-form&#x27;</span>)</span></span><br><span class="line"><span class="language-javascript">      <span class="keyword">const</span> data = <span class="title function_">serialize</span>(form, &#123; <span class="attr">hash</span>: <span class="literal">true</span>, <span class="attr">empty</span>: <span class="literal">true</span> &#125;)</span></span><br><span class="line"><span class="language-javascript">      <span class="comment">// const data = serialize(form, &#123; hash: false, empty: true &#125;)</span></span></span><br><span class="line"><span class="language-javascript">      <span class="comment">// const data = serialize(form, &#123; hash: true, empty: false &#125;)</span></span></span><br><span class="line"><span class="language-javascript">      <span class="variable language_">console</span>.<span class="title function_">log</span>(data)</span></span><br><span class="line"><span class="language-javascript">    &#125;)</span></span><br><span class="line"><span class="language-javascript">  </span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure></li></ol><h3 id="小结-12"><a href="#小结-12" class="headerlink" title="小结"></a>小结</h3><ol><li><p>我们什么时候使用 form-serialize 插件？</p><details><summary>答案</summary><ul><li>快速收集表单元素的值</li></ul></details></li><li><p>如何使用 form-serialize 插件？</p><details><summary>答案</summary><ul><li>1. 先引入插件到自己的网页中，2. 准备form和表单元素的name属性，3.使用serialize函数，传入form表单和配置对象</li></ul></details></li><li><p>配置对象中 hash 和 empty 有什么用？</p><details><summary>答案</summary><ul><li>hash 决定是收集为 JS 对象还是查询参数字符串，empty 决定是否收集空值</li></ul></details></li></ol><h2 id="14-案例-用户登录-form-serialize"><a href="#14-案例-用户登录-form-serialize" class="headerlink" title="14.案例-用户登录-form-serialize"></a>14.案例-用户登录-form-serialize</h2><h3 id="目标-13"><a href="#目标-13" class="headerlink" title="目标"></a>目标</h3><ul><li>尝试通过 form-serialize 重新修改用户登录案例-收集用户名和密码</li></ul><h3 id="讲解-13"><a href="#讲解-13" class="headerlink" title="讲解"></a>讲解</h3><ol><li>基于模板代码，使用 form-serialize 插件来收集用户名和密码</li><li>在原来的代码基础上修改即可</li></ol><h3 id="小结-13"><a href="#小结-13" class="headerlink" title="小结"></a>小结</h3><ol><li><p>如何把一个第三方插件使用在已完成的案例中？</p><details><summary>答案</summary><ul><li>引入后，只需要使用在要修改的地方，修改一点就要确认测试一下</li></ul></details></li></ol><h2 id="今日重点-必须会"><a href="#今日重点-必须会" class="headerlink" title="今日重点(必须会)"></a>今日重点(必须会)</h2><ol><li>axios 的配置项有哪几个，作用分别是什么？</li><li>接口文档都包含哪些信息？</li><li>在浏览器中如何查看查询参数&#x2F;请求体，以及响应体数据？</li><li>请求报文和响应报文由几个部分组成，每个部分的作用？</li></ol><h2 id="今日作业-必完成"><a href="#今日作业-必完成" class="headerlink" title="今日作业(必完成)"></a>今日作业(必完成)</h2><p>参考作业文件夹的md要求</p><h2 id="参考文献"><a href="#参考文献" class="headerlink" title="参考文献"></a>参考文献</h2><ol><li><a target="_blank" rel="noopener" href="https://baike.baidu.com/item/%E5%AE%A2%E6%88%B7%E7%AB%AF/101081?fr=aladdin">客户端-&gt;百度百科</a></li><li><a target="_blank" rel="noopener" href="https://baike.baidu.com/item/%E6%B5%8F%E8%A7%88%E5%99%A8/213911?fr=aladdin">浏览器解释-&gt;百度百科</a></li><li><a target="_blank" rel="noopener" href="https://baike.baidu.com/item/%E6%9C%8D%E5%8A%A1%E5%99%A8/100571?fr=aladdin">服务器解释-&gt;百度百科</a></li><li><a target="_blank" rel="noopener" href="https://baike.baidu.com/item/%E7%BB%9F%E4%B8%80%E8%B5%84%E6%BA%90%E5%AE%9A%E4%BD%8D%E7%B3%BB%E7%BB%9F/5937042?fromtitle=URL&fromid=110640&fr=aladdin">url解释-&gt;百度百科</a></li><li><a target="_blank" rel="noopener" href="https://baike.baidu.com/item/HTTP?fromtitle=HTTP%E5%8D%8F%E8%AE%AE&fromid=1276942">http协议-&gt;百度百科</a></li><li><a target="_blank" rel="noopener" href="https://baike.baidu.com/item/%E4%B8%BB%E6%9C%BA%E5%90%8D">主机名-&gt;百度百科</a></li><li><a target="_blank" rel="noopener" href="https://baike.baidu.com/item/%E7%AB%AF%E5%8F%A3%E5%8F%B">端口号-&gt;百度百科</a></li><li><a target="_blank" rel="noopener" href="https://baike.baidu.com/tashuo/browse/content?id=11fca6ecdc2c066af4c5594f&lemmaId=8425&fromLemmaModule=pcBottom&lemmaTitle=ajax">Ajax解释-&gt;百度-懂啦</a></li><li><a target="_blank" rel="noopener" href="https://developer.mozilla.org/zh-CN/docs/Web/Guide/AJAX/Getting_Started">Ajax解释-&gt;MDN解释Ajax是与服务器通信而不只是请求</a></li><li><a target="_blank" rel="noopener" href="https://baike.baidu.com/item/axios">axios-&gt;百度(可以点击播报听读音)</a></li><li><a target="_blank" rel="noopener" href="https://github.com/axios/axios">axios(github)地址</a></li><li><a target="_blank" rel="noopener" href="https://axios-http.com/">axios官方推荐官网</a></li><li><a target="_blank" rel="noopener" href="https://www.npmjs.com/package/axios">axios(npmjs)地址</a></li><li><a target="_blank" rel="noopener" href="https://baike.baidu.com/item/post/2171305">GET和POST区别-&gt;百度百科</a></li><li><a target="_blank" rel="noopener" href="https://baike.baidu.com/item/%E6%8A%A5%E6%96%87/3164352">报文讲解-&gt;百度百科</a></li><li><a target="_blank" rel="noopener" href="https://baike.baidu.com/item/HTTP%E7%8A%B6%E6%80%81%E7%A0%81/5053660">HTTP状态码-&gt;百度百科</a></li><li><a target="_blank" rel="noopener" href="https://baike.baidu.com/item/%E6%8E%A5%E5%8F%A3/2886384">接口概念-&gt;百度百科</a></li></ol><h1 id="Day01-AJAX入门"><a href="#Day01-AJAX入门" class="headerlink" title="Day01_AJAX入门"></a>Day01_AJAX入门</h1><h2 id="客观题"><a href="#客观题" class="headerlink" title="客观题"></a>客观题</h2><ul><li><p>参考客观题目录下的excel</p></li><li><p>在线直接答题：<a target="_blank" rel="noopener" href="https://ks.wjx.top/vm/OrYaZ1x.aspx#">https://ks.wjx.top/vm/OrYaZ1x.aspx#</a></p><blockquote><p>ps：本测试链接来自问卷星，请不要轻信问卷星广告！</p></blockquote></li></ul><h2 id="主观题"><a href="#主观题" class="headerlink" title="主观题"></a>主观题</h2><h3 id="作业1-微信聊天"><a href="#作业1-微信聊天" class="headerlink" title="作业1 - 微信聊天"></a>作业1 - 微信聊天</h3><p>目标：完成如下聊天效果</p><p>要求：</p><ol><li>点击发送和敲击回车键，都能发送聊天消息</li><li>把自己和对方消息都展示到页面上</li><li>当聊天消息出现滚动条时，始终让最后一条消息出现在视口范围内</li></ol><p>接口文档：<a target="_blank" rel="noopener" href="https://www.apifox.cn/apidoc/project-1937884/api-49760222">https://www.apifox.cn/apidoc/project-1937884/api-49760222</a></p><p>效果如下：配套标签和样式在文件夹内</p><img src="" data-lazy-src="https://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/hm8.1ajax/homework_chat.gif" alt="homework_chat" style="zoom:33%"><h3 id="作业2-必要商城搜索"><a href="#作业2-必要商城搜索" class="headerlink" title="作业2 - 必要商城搜索"></a>作业2 - 必要商城搜索</h3><p>目标：完成如下搜索效果</p><p>要求：</p><ol><li>输入要搜索的关键字，点击放大镜搜索匹配商品</li></ol><p>接口文档：<a target="_blank" rel="noopener" href="https://www.apifox.cn/apidoc/project-1937884/api-63538670">https://www.apifox.cn/apidoc/project-1937884/api-63538670</a></p><p>效果如下：配套标签和样式在文件夹内</p><img src="" data-lazy-src="https://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/hm8.1ajax/%E5%BF%85%E8%A6%81%E5%95%86%E5%9F%8E%E6%90%9C%E7%B4%A2.gif" alt="必要商城搜索" style="zoom:33%"><h2 id="排错题"><a href="#排错题" class="headerlink" title="排错题"></a>排错题</h2><p>配套文件夹内的《案例-登录》里面有 6 处错误，请帮帮这位同学实现登录效果吧</p><h2 id="面试题"><a href="#面试题" class="headerlink" title="面试题"></a>面试题</h2><h3 id="1-GET-和-POST-请求方法的区别？"><a href="#1-GET-和-POST-请求方法的区别？" class="headerlink" title="1. GET 和 POST 请求方法的区别？"></a>1. GET 和 POST 请求方法的区别？</h3><ol><li><p>GET和POST请求方式无区别, 本质都是一次HTTP请求(TCP链接), 而HTTP请求报文中都包含请求行, 请求头, 请求体，我们可以在相应位置携带值给服务器</p></li><li><p>图解: <img src="" data-lazy-src="https://yjy-teach-oss.oss-cn-beijing.aliyuncs.com/hm8.1ajax/1665631819952-57c52b31-b574-4e25-8c2a-b3a989c2523e.png" alt="img" style="zoom:80%"></p></li><li><p>但是<a target="_blank" rel="noopener" href="https://xhr.spec.whatwg.org/#the-send()-method">GET或HEAD请求方式, 浏览器会忽略请求体</a>, 但不代表GET&#x2F;HEAD方式无法发送请求体, 使用apifox等接口调试工具是可以携带请求体的</p></li><li><p>非要说区别有如下几点</p><ol><li>浏览器回退的时候, GET不会重新提交, 而POST会重新提交表单</li><li>GET会被浏览器主动缓存, POST不会</li><li>再就是url上传查询参数和请求体传参的区别了(实际上不是GET和POST区别了)<ul><li>url上只能进行url编码, 而请求体里支持多种编码格式</li><li>url上的参数会保留在浏览器历史记录里, 而请求体不会被保留, 除非用代码设置</li></ul></li></ol></li></ol><h3 id="2-原生Ajax的原理"><a href="#2-原生Ajax的原理" class="headerlink" title="2. 原生Ajax的原理?"></a>2. 原生Ajax的原理?</h3><blockquote><p>axios库是对原生Ajax的XMLHttpRequest相关语法的封装</p><p>AJAX 原理是 XMLHttpRequest 相关语法</p><p>而原生JS代码参考如下文档↓</p></blockquote><p><a target="_blank" rel="noopener" href="https://lamphc.github.io/fe-up/#/JavaScript/ajax?id=%e9%9d%a2%e8%af%95%e5%ae%98%ef%bc%9aajax%e5%8e%9f%e7%90%86%e6%98%af%e4%bb%80%e4%b9%88%ef%bc%9f%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%ef%bc%9f">点我看答案</a></p><h3 id="3-箭头函数和function函数区别"><a href="#3-箭头函数和function函数区别" class="headerlink" title="3. 箭头函数和function函数区别?"></a>3. 箭头函数和function函数区别?</h3><p>箭头函数常用做回调函数使用, 它无自己的this, 无arguments对象, 不能被new调用</p><h3 id="4-一个页面从输入-URL-到页面加载显示完成，这个过程中都发生了什么"><a href="#4-一个页面从输入-URL-到页面加载显示完成，这个过程中都发生了什么" class="headerlink" title="4. 一个页面从输入 URL 到页面加载显示完成，这个过程中都发生了什么"></a>4. 一个页面从输入 URL 到页面加载显示完成，这个过程中都发生了什么</h3><ol><li>浏览器查找域名对应的 IP 地址(DNS 查询：浏览器缓存-&gt;系统缓存-&gt;路由器缓存-&gt;ISPDNS 缓存-&gt;根域名服务器)</li><li>浏览器向 Web 服务器发送一个 HTTP 请求（TCP 三次握手）</li><li>（如果服务器设置了重定向）服务器 301 重定向（从 HTTP:&#x2F;&#x2F;example.com 重定向到 HTTP:&#x2F;&#x2F;<a target="_blank" rel="noopener" href="http://www.example.com)/">www.example.com）</a></li><li>浏览器跟踪重定向地址，请求另一个带 www 的网址</li><li>服务器处理请求（通过路由读取资源）</li><li>服务器返回一个 HTTP 响应（报头中把 Content-type 设置为 ‘text&#x2F;html’）</li><li>浏览器进 DOM 树构建</li><li>浏览器发送请求获取嵌在 HTML 中的资源（如图片、音频、视频、CSS、JS 等）</li><li>浏览器显示完成页面</li><li>浏览器发送异步请求</li></ol></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">本文作者:</span> <span class="post-copyright-info"><a href="https://webxc.eu.org">XC's Blog</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">本文链接:</span> <span class="post-copyright-info"><a href="https://webxc.eu.org/post/as67/">https://webxc.eu.org/post/as67/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明:</span> <span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://webxc.eu.org" target="_blank">XC's Blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/Ajax%E7%AC%94%E8%AE%B0/">Ajax笔记</a></div><div class="post_share"><div class="social-share" data-image="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/ajax.webp" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://npm.elemecdn.com/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload='this.media="all"'><script src="https://npm.elemecdn.com/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="https://npm.elemecdn.com/webxc@1.0.0/lxfs/wechat.png" target="_blank"><img class="post-qr-code-img" src="https://npm.elemecdn.com/webxc@1.0.0/lxfs/wechat.png" alt="Wechat"></a><div class="post-qr-code-desc">Wechat</div></li><li class="reward-item"><a href="https://npm.elemecdn.com/webxc@1.0.0/lxfs/alipay.jpg" target="_blank"><img class="post-qr-code-img" src="https://npm.elemecdn.com/webxc@1.0.0/lxfs/alipay.jpg" alt="Alipay"></a><div class="post-qr-code-desc">Alipay</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/post/de23/"><img class="prev-cover" src="https://npm.elemecdn.com/webxc/cover/js1.webp" onerror='onerror=null,src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇文章</div><div class="prev_info">JS进阶复习</div></div></a></div><div class="next-post pull-right"><a href="/post/aw67/"><img class="next-cover" src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/ajax.webp" onerror='onerror=null,src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="cover of next post"><div class="pagination-info"><div class="label">下一篇文章</div><div class="next_info">Ajax第二天</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/post/fs67/" title="Ajax第三天"><img class="cover" src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/ajax.webp" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-06-07</div><div class="title">Ajax第三天</div></div></a></div><div><a href="/post/or01/" title="Ajax第四天"><img class="cover" src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/ajax.webp" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-06-08</div><div class="title">Ajax第四天</div></div></a></div><div><a href="/post/pr67/" title="ES6-Promise语法与原理"><img class="cover" src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/promise.webp" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-06-11</div><div class="title">ES6-Promise语法与原理</div></div></a></div></div></div><hr><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i> <span>评论</span></div></div><div class="comment-wrap"><div><div id="twikoo-wrap"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://npm.elemecdn.com/webxc@1.0.0/logo/logo.jpg" onerror='this.onerror=null,this.src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="avatar"></div><div class="author-info__name">XC's Blog</div><div class="author-info__description">XC's Blog 记录生活和学习文章</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">95</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">25</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">25</div></a></div><div class="card-info-social-icons is-center"><a class="social-icon" href="https://tenapi.cn/qqzlk/?qq=2848141597" target="_blank" title="QQ"><i class="iconfont icon-QQ"></i></a><a class="social-icon" href="https://npm.elemecdn.com/webxc@1.0.0/lxfs/wechat.jpg" target="_blank" title="微信"><i class="iconfont icon-weixin"></i></a><a class="social-icon" href="https://github.com/web-xc" target="_blank" title="Github"><i class="iconfont icon-github"></i></a><a class="social-icon" href="https://space.bilibili.com/2134826455" target="_blank" title="BiliBili"><i class="iconfont icon-bilibili"></i></a><a class="social-icon" href="https://music.163.com/#/user/home?id=323682437" target="_blank" title="网易云音乐"><i class="iconfont icon-wyy"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">原网站因使用.ml域名被回收, 再加上本人因学习原因, 没怎么打理博客, 使用了https://webxc.eu.org域名来维持博客运行, 如果有加友联的朋友们, 去友联页看信息即可, 如果原来有加过的, 麻烦在原来域名后缀改一下(.ml ==> .eu.org)就行, 博客写的太乱了, 没时间打理, 兄弟们谅解😁😁~~</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#Ajax%E7%AC%AC%E4%B8%80%E5%A4%A9-%E2%80%93-ajax%E6%A6%82%E5%BF%B5-%E2%80%93-axios%E7%9A%84%E4%BD%BF%E7%94%A8-%E2%80%93-HTTP%E5%8D%8F%E8%AE%AE"><span class="toc-number">1.</span> <span class="toc-text">Ajax第一天 – ajax概念 – axios的使用 – HTTP协议</span></a></li></ol><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%9F%A5%E8%AF%86%E7%82%B9%E8%87%AA%E6%B5%8B"><span class="toc-number"></span> <span class="toc-text">知识点自测</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%9B%AE%E5%BD%95"><span class="toc-number"></span> <span class="toc-text">目录</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AD%A6%E4%B9%A0%E7%9B%AE%E6%A0%87"><span class="toc-number"></span> <span class="toc-text">学习目标</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#01-AJAX-%E6%A6%82%E5%BF%B5%E5%92%8C-axios-%E4%BD%BF%E7%94%A8"><span class="toc-number"></span> <span class="toc-text">01.AJAX 概念和 axios 使用</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%9B%AE%E6%A0%87"><span class="toc-number">1.</span> <span class="toc-text">目标</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%AE%B2%E8%A7%A3"><span class="toc-number">2.</span> <span class="toc-text">讲解</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B0%8F%E7%BB%93"><span class="toc-number">3.</span> <span class="toc-text">小结</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#02-%E8%AE%A4%E8%AF%86-URL"><span class="toc-number"></span> <span class="toc-text">02.认识 URL</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%9B%AE%E6%A0%87-1"><span class="toc-number">1.</span> <span class="toc-text">目标</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%AE%B2%E8%A7%A3-1"><span class="toc-number">2.</span> <span class="toc-text">讲解</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B0%8F%E7%BB%93-1"><span class="toc-number">3.</span> <span class="toc-text">小结</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#03-URL-%E6%9F%A5%E8%AF%A2%E5%8F%82%E6%95%B0"><span class="toc-number"></span> <span class="toc-text">03.URL 查询参数</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%9B%AE%E6%A0%87-2"><span class="toc-number">1.</span> <span class="toc-text">目标</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%AE%B2%E8%A7%A3-2"><span class="toc-number">2.</span> <span class="toc-text">讲解</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B0%8F%E7%BB%93-2"><span class="toc-number">3.</span> <span class="toc-text">小结</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#04-%E6%A1%88%E4%BE%8B-%E6%9F%A5%E8%AF%A2-%E5%9C%B0%E5%8C%BA%E5%88%97%E8%A1%A8"><span class="toc-number"></span> <span class="toc-text">04.案例-查询-地区列表</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%9B%AE%E6%A0%87-3"><span class="toc-number">1.</span> <span class="toc-text">目标</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%AE%B2%E8%A7%A3-3"><span class="toc-number">2.</span> <span class="toc-text">讲解</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B0%8F%E7%BB%93-3"><span class="toc-number">3.</span> <span class="toc-text">小结</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#05-%E5%B8%B8%E7%94%A8%E8%AF%B7%E6%B1%82%E6%96%B9%E6%B3%95%E5%92%8C%E6%95%B0%E6%8D%AE%E6%8F%90%E4%BA%A4"><span class="toc-number"></span> <span class="toc-text">05.常用请求方法和数据提交</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%9B%AE%E6%A0%87-4"><span class="toc-number">1.</span> <span class="toc-text">目标</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%AE%B2%E8%A7%A3-4"><span class="toc-number">2.</span> <span class="toc-text">讲解</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B0%8F%E7%BB%93-4"><span class="toc-number">3.</span> <span class="toc-text">小结</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#06-axios-%E9%94%99%E8%AF%AF%E5%A4%84%E7%90%86"><span class="toc-number"></span> <span class="toc-text">06.axios 错误处理</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%9B%AE%E6%A0%87-5"><span class="toc-number">1.</span> <span class="toc-text">目标</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%AE%B2%E8%A7%A3-5"><span class="toc-number">2.</span> <span class="toc-text">讲解</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B0%8F%E7%BB%93-5"><span class="toc-number">3.</span> <span class="toc-text">小结</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#07-HTTP-%E5%8D%8F%E8%AE%AE-%E8%AF%B7%E6%B1%82%E6%8A%A5%E6%96%87"><span class="toc-number"></span> <span class="toc-text">07.HTTP 协议-请求报文</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%9B%AE%E6%A0%87-6"><span class="toc-number">1.</span> <span class="toc-text">目标</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%AE%B2%E8%A7%A3-6"><span class="toc-number">2.</span> <span class="toc-text">讲解</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B0%8F%E7%BB%93-6"><span class="toc-number">3.</span> <span class="toc-text">小结</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#08-%E8%AF%B7%E6%B1%82%E6%8A%A5%E6%96%87-%E9%94%99%E8%AF%AF%E6%8E%92%E6%9F%A5"><span class="toc-number"></span> <span class="toc-text">08.请求报文-错误排查</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%9B%AE%E6%A0%87-7"><span class="toc-number">1.</span> <span class="toc-text">目标</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%AE%B2%E8%A7%A3-7"><span class="toc-number">2.</span> <span class="toc-text">讲解</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B0%8F%E7%BB%93-7"><span class="toc-number">3.</span> <span class="toc-text">小结</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#09-HTTP-%E5%8D%8F%E8%AE%AE-%E5%93%8D%E5%BA%94%E6%8A%A5%E6%96%87"><span class="toc-number"></span> <span class="toc-text">09.HTTP 协议-响应报文</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%9B%AE%E6%A0%87-8"><span class="toc-number">1.</span> <span class="toc-text">目标</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%AE%B2%E8%A7%A3-8"><span class="toc-number">2.</span> <span class="toc-text">讲解</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B0%8F%E7%BB%93-8"><span class="toc-number">3.</span> <span class="toc-text">小结</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#10-%E6%8E%A5%E5%8F%A3%E6%96%87%E6%A1%A3"><span class="toc-number"></span> <span class="toc-text">10.接口文档</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%9B%AE%E6%A0%87-9"><span class="toc-number">1.</span> <span class="toc-text">目标</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%AE%B2%E8%A7%A3-9"><span class="toc-number">2.</span> <span class="toc-text">讲解</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B0%8F%E7%BB%93-9"><span class="toc-number">3.</span> <span class="toc-text">小结</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#11-%E6%A1%88%E4%BE%8B-%E7%94%A8%E6%88%B7%E7%99%BB%E5%BD%95-%E4%B8%BB%E8%A6%81%E4%B8%9A%E5%8A%A1"><span class="toc-number"></span> <span class="toc-text">11.案例-用户登录-主要业务</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%9B%AE%E6%A0%87-10"><span class="toc-number">1.</span> <span class="toc-text">目标</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%AE%B2%E8%A7%A3-10"><span class="toc-number">2.</span> <span class="toc-text">讲解</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B0%8F%E7%BB%93-10"><span class="toc-number">3.</span> <span class="toc-text">小结</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#12-%E6%A1%88%E4%BE%8B-%E7%94%A8%E6%88%B7%E7%99%BB%E5%BD%95-%E6%8F%90%E7%A4%BA%E4%BF%A1%E6%81%AF"><span class="toc-number"></span> <span class="toc-text">12.案例-用户登录-提示信息</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%9B%AE%E6%A0%87-11"><span class="toc-number">1.</span> <span class="toc-text">目标</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%AE%B2%E8%A7%A3-11"><span class="toc-number">2.</span> <span class="toc-text">讲解</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B0%8F%E7%BB%93-11"><span class="toc-number">3.</span> <span class="toc-text">小结</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#13-form-serialize-%E6%8F%92%E4%BB%B6"><span class="toc-number"></span> <span class="toc-text">13.form-serialize 插件</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%9B%AE%E6%A0%87-12"><span class="toc-number">1.</span> <span class="toc-text">目标</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%AE%B2%E8%A7%A3-12"><span class="toc-number">2.</span> <span class="toc-text">讲解</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B0%8F%E7%BB%93-12"><span class="toc-number">3.</span> <span class="toc-text">小结</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#14-%E6%A1%88%E4%BE%8B-%E7%94%A8%E6%88%B7%E7%99%BB%E5%BD%95-form-serialize"><span class="toc-number"></span> <span class="toc-text">14.案例-用户登录-form-serialize</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%9B%AE%E6%A0%87-13"><span class="toc-number">1.</span> <span class="toc-text">目标</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%AE%B2%E8%A7%A3-13"><span class="toc-number">2.</span> <span class="toc-text">讲解</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B0%8F%E7%BB%93-13"><span class="toc-number">3.</span> <span class="toc-text">小结</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BB%8A%E6%97%A5%E9%87%8D%E7%82%B9-%E5%BF%85%E9%A1%BB%E4%BC%9A"><span class="toc-number"></span> <span class="toc-text">今日重点(必须会)</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BB%8A%E6%97%A5%E4%BD%9C%E4%B8%9A-%E5%BF%85%E5%AE%8C%E6%88%90"><span class="toc-number"></span> <span class="toc-text">今日作业(必完成)</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8F%82%E8%80%83%E6%96%87%E7%8C%AE"><span class="toc-number"></span> <span class="toc-text">参考文献</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Day01-AJAX%E5%85%A5%E9%97%A8"><span class="toc-number"></span> <span class="toc-text">Day01_AJAX入门</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%A2%E8%A7%82%E9%A2%98"><span class="toc-number"></span> <span class="toc-text">客观题</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%BB%E8%A7%82%E9%A2%98"><span class="toc-number"></span> <span class="toc-text">主观题</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BD%9C%E4%B8%9A1-%E5%BE%AE%E4%BF%A1%E8%81%8A%E5%A4%A9"><span class="toc-number">1.</span> <span class="toc-text">作业1 - 微信聊天</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BD%9C%E4%B8%9A2-%E5%BF%85%E8%A6%81%E5%95%86%E5%9F%8E%E6%90%9C%E7%B4%A2"><span class="toc-number">2.</span> <span class="toc-text">作业2 - 必要商城搜索</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%8E%92%E9%94%99%E9%A2%98"><span class="toc-number"></span> <span class="toc-text">排错题</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%9D%A2%E8%AF%95%E9%A2%98"><span class="toc-number"></span> <span class="toc-text">面试题</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-GET-%E5%92%8C-POST-%E8%AF%B7%E6%B1%82%E6%96%B9%E6%B3%95%E7%9A%84%E5%8C%BA%E5%88%AB%EF%BC%9F"><span class="toc-number">1.</span> <span class="toc-text">1. GET 和 POST 请求方法的区别？</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E5%8E%9F%E7%94%9FAjax%E7%9A%84%E5%8E%9F%E7%90%86"><span class="toc-number">2.</span> <span class="toc-text">2. 原生Ajax的原理?</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-%E7%AE%AD%E5%A4%B4%E5%87%BD%E6%95%B0%E5%92%8Cfunction%E5%87%BD%E6%95%B0%E5%8C%BA%E5%88%AB"><span class="toc-number">3.</span> <span class="toc-text">3. 箭头函数和function函数区别?</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-%E4%B8%80%E4%B8%AA%E9%A1%B5%E9%9D%A2%E4%BB%8E%E8%BE%93%E5%85%A5-URL-%E5%88%B0%E9%A1%B5%E9%9D%A2%E5%8A%A0%E8%BD%BD%E6%98%BE%E7%A4%BA%E5%AE%8C%E6%88%90%EF%BC%8C%E8%BF%99%E4%B8%AA%E8%BF%87%E7%A8%8B%E4%B8%AD%E9%83%BD%E5%8F%91%E7%94%9F%E4%BA%86%E4%BB%80%E4%B9%88"><span class="toc-number">4.</span> <span class="toc-text">4. 一个页面从输入 URL 到页面加载显示完成，这个过程中都发生了什么</span></a></li></ol></li></ol></li></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/post/ds2s/" title="整个前端面试题"><img src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png" onerror='this.onerror=null,this.src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="整个前端面试题"></a><div class="content"><a class="title" href="/post/ds2s/" title="整个前端面试题">整个前端面试题</a><time datetime="2023-08-31T02:00:00.000Z" title="发表于 2023-08-31 02:00:00">2023-08-31</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/post/ds23/" title="常见前端面试题"><img src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png" onerror='this.onerror=null,this.src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="常见前端面试题"></a><div class="content"><a class="title" href="/post/ds23/" title="常见前端面试题">常见前端面试题</a><time datetime="2023-08-28T18:30:00.000Z" title="发表于 2023-08-28 18:30:00">2023-08-28</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/post/fe33/" title="硅谷甄选运营平台"><img src="https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png" onerror='this.onerror=null,this.src="https://npm.elemecdn.com/webxc@1.0.2/banner/404.gif"' alt="硅谷甄选运营平台"></a><div class="content"><a class="title" href="/post/fe33/" title="硅谷甄选运营平台">硅谷甄选运营平台</a><time datetime="2023-07-26T03:55:00.000Z" title="发表于 2023-07-26 03:55:00">2023-07-26</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2021 - 2023 By XC's Blog</div><div class="framework-info"><span></span> <a target="_blank" rel="noopener" href="https://icp.gov.moe/?keyword=20235221">萌ICP备20235221号</a><span class="footer-separator">|</span><span></span> <a target="_blank" rel="noopener" href="https://icp.gov.moe/">萌ICP查询</a><div id="running-time"></div></div><script>setInterval((()=>{let e=Math.round(new Date("2021-11-21 01:35:06").getTime()/1e3),t=Math.round(((new Date).getTime()+288e5)/1e3)-e,n=new Array(0,0,0,0,0);t>=31536e3&&(n[0]=parseInt(t/31536e3),t%=31536e3),t>=86400&&(n[1]=parseInt(t/86400),t%=86400),t>=3600&&(n[2]=parseInt(t/3600),t%=3600),t>=60&&(n[3]=parseInt(t/60),t%=60),t>0&&(n[4]=t),currentTimeHtml="本站已安全运行 "+n[0]+" 年 "+n[1]+" 天 "+n[2]+" 时 "+n[3]+" 分 "+n[4]+" 秒",document.getElementById("running-time").innerHTML=currentTimeHtml}),1e3)</script></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i><span id="percent">0<span>%</span></span></button><button id="go-down" type="button" title="直达底部" onclick="btf.scrollToDest(document.body.scrollHeight,500)"><i class="fas fa-arrow-down"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i> <span>正在载入文件,请稍后</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"></div></div><hr><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="https://npm.elemecdn.com/hexo-theme-butterfly/source/js/utils.js"></script><script src="https://npm.elemecdn.com/hexo-theme-butterfly@4.4.0/source/js/main.js"></script><script src="https://npm.elemecdn.com/@fancyapps/ui/dist/fancybox.umd.js"></script><script src="https://npm.elemecdn.com/instant.page/instantpage.js" type="module"></script><script src="https://npm.elemecdn.com/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="https://npm.elemecdn.com/node-snackbar/dist/snackbar.min.js"></script><script src="https://npm.elemecdn.com/hexo-theme-butterfly/source/js/search/local-search.js"></script><div class="js-pjax"><script>(()=>{const e=document.querySelectorAll("#article-container .mermaid-wrap");if(e.length){window.runMermaid=()=>{window.loadMermaid=!0;const t="dark"===document.documentElement.getAttribute("data-theme")?"dark":"default";Array.from(e).forEach(((e,n)=>{const d=e.firstElementChild,r="mermaid-"+n,m="%%{init:{ 'theme':'"+t+"'}}%%\n"+d.textContent;mermaid.mermaidAPI.render(r,m,(e=>{d.insertAdjacentHTML("afterend",e)}))}))};const t=()=>{window.loadMermaid?runMermaid():getScript("https://npm.elemecdn.com/mermaid/dist/mermaid.min.js").then(runMermaid)};window.pjax?t():document.addEventListener("DOMContentLoaded",t)}})()</script><script>(()=>{const o=()=>{twikoo.init(Object.assign({el:"#twikoo-wrap",envId:"https://blog2.webxc.eu.org/",region:"",onCommentLoaded:function(){btf.loadLightbox(document.querySelectorAll("#twikoo .tk-content img:not(.tk-owo-emotion)"))}},null))},t=()=>{"object"!=typeof twikoo?getScript("https://npm.elemecdn.com/twikoo@1.6.16/dist/twikoo.all.min.js").then(o):setTimeout(o,0)};t()})()</script></div><script data-pjax="false" defer src="https://npm.elemecdn.com/webxc@1.0.16/css/style.js"></script><script defer src="https://npm.elemecdn.com/hexo-theme-butterfly@4.4.0/source/js/search/local-search.js"></scrip><script src="https://npm.elemecdn.com/butterfly-extsrc/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful=!0,POWERMODE.shake=!0,POWERMODE.mobile=!0,document.body.addEventListener("input",POWERMODE)</script><script src="https://npm.elemecdn.com/pjax@0.2.8/pjax.min.js"></script><script>let pjaxSelectors=["head > title","#config-diff","#body-wrap","#rightside-config-hide","#rightside-config-show",".js-pjax",".tk-comments-container"];var pjax=new Pjax({elements:'a:not([target="_blank"])',selectors:pjaxSelectors,cacheBust:!1,analytics:!1,scrollRestoration:!1});document.addEventListener("pjax:send",(function(){if(window.tocScrollFn&&window.removeEventListener("scroll",window.tocScrollFn),window.scrollCollect&&window.removeEventListener("scroll",scrollCollect),"object"==typeof preloader&&preloader.initLoading(),document.getElementById("rightside").style.cssText="opacity: ''; transform: ''",window.aplayers)for(let e=0;e<window.aplayers.length;e++)window.aplayers[e].options.fixed||window.aplayers[e].destroy();"object"==typeof typed&&typed.destroy();const e=document.body.classList;e.contains("read-mode")&&e.remove("read-mode"),"object"==typeof disqusjs&&disqusjs.destroy()})),document.addEventListener("pjax:complete",(function(){window.refreshFn(),document.querySelectorAll("script[data-pjax]").forEach((e=>{const t=document.createElement("script"),o=e.text||e.textContent||e.innerHTML||"";Array.from(e.attributes).forEach((e=>t.setAttribute(e.name,e.value))),t.appendChild(document.createTextNode(o)),e.parentNode.replaceChild(t,e)})),GLOBAL_CONFIG.islazyload&&window.lazyLoadInstance.update(),"function"==typeof chatBtnFn&&chatBtnFn(),"function"==typeof panguInit&&panguInit(),"function"==typeof gtag&&gtag("config","",{page_path:window.location.pathname}),"object"==typeof _hmt&&_hmt.push(["_trackPageview",window.location.pathname]),"function"==typeof loadMeting&&document.getElementsByClassName("aplayer").length&&loadMeting(),"object"==typeof Prism&&Prism.highlightAll(),"object"==typeof preloader&&preloader.endLoading()})),document.addEventListener("pjax:error",(e=>{404===e.request.status&&pjax.loadUrl("/404.html")}))</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><script data-pjax>function butterfly_swiper_injector_config(){var s=document.getElementById("recent-posts");console.log("已挂载butterfly_swiper"),s.insertAdjacentHTML("afterbegin",'<div class="recent-post-item" style="height: auto;width: 100%"><div class="blog-slider swiper-container-fade swiper-container-horizontal" id="swiper_container"><div class="blog-slider__wrp swiper-wrapper" style="transition-duration: 0ms;"><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-08-31</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/ds2s/&quot;);" href="javascript:void(0);" alt="">整个前端面试题</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-08-28</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/ds23/&quot;);" href="javascript:void(0);" alt="">常见前端面试题</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-07-26</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/fe33/&quot;);" href="javascript:void(0);" alt="">硅谷甄选运营平台</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-07-17</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/ew32/&quot;);" href="javascript:void(0);" alt="">Vue第三天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-07-16</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/aw92/&quot;);" href="javascript:void(0);" alt="">Vue第二天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-07-14</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/ou67/&quot;);" href="javascript:void(0);" alt="">Vue第一天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/vue.png);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-07-05</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/fn32/&quot;);" href="javascript:void(0);" alt="">Vue框架笔记</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc/cover/js1.webp);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-06-21</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/fe11/&quot;);" href="javascript:void(0);" alt="">Vue前置JS功底</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/promise.webp);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-06-11</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/pr67/&quot;);" href="javascript:void(0);" alt="">ES6-Promise语法与原理</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/ajax.webp);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-06-08</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/or01/&quot;);" href="javascript:void(0);" alt="">Ajax第四天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://cdn1.tianli0.top/gh/web-xc/iMG/postss/ajax.webp);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-06-07</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/fs67/&quot;);" href="javascript:void(0);" alt="">Ajax第三天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc/cover/js1.webp);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-05-11</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/fe66/&quot;);" href="javascript:void(0);" alt="">JS进阶第四天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc/cover/js1.webp);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-05-10</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/fe99/&quot;);" href="javascript:void(0);" alt="">JS进阶第三天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc/cover/js1.webp);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2023-05-05</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/us87/&quot;);" href="javascript:void(0);" alt="">JS进阶第二天</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc@1.0.12/cover/cover15.jpg);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2022-10-31</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/2db5/&quot;);" href="javascript:void(0);" alt="">移动开发-Flex布局</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc@1.0.12/cover/cover16.jpg);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2022-11-14</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/1c7e/&quot;);" href="javascript:void(0);" alt="">移动开发-媒体查询</a><div class="blog-slider__text">点击查看</div></div></div><div class="blog-slider__item swiper-slide" style="background:url(https://npm.elemecdn.com/webxc@1.0.12/cover/cover17.jpg);border-radius:12px;opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><div class="blog-slider__content"><span class="blog-slider__code">2022-11-17</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;post/7fc/&quot;);" href="javascript:void(0);" alt="">移动开发-响应式</a><div class="blog-slider__text">点击查看</div></div></div></div><div class="blog-slider__pagination swiper-pagination-clickable swiper-pagination-bullets"></div><div class="swiper-button-prev"></div><div class="swiper-button-next"></div></div></div>')}for(var elist="null".split(","),cpage=location.pathname,epage="all",flag=0,i=0;i<elist.length;i++)cpage.includes(elist[i])&&flag++;("all"===epage&&0==flag||epage===cpage)&&butterfly_swiper_injector_config()</script><script defer src="https://npm.elemecdn.com/webxc@1.0.12/css/swiper/swiper.min.js"></script><script defer data-pjax src="https://npm.elemecdn.com/webxc@1.0.12/css/swiper/swiper_init.js"></script></body></html>